package com.llyb.chap06;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableDemo {

    public static void main(String[] args) {
        Callable<String> callable = new Callable() {
            /**
             * Computes a result, or throws an exception if unable to do so.
             *
             * @return computed result
             * @throws Exception if unable to compute a result
             */
            @Override
            public String call() throws Exception {
                System.out.println(Thread.currentThread().getName() + "\t" + "---- come in");
                return "ok";
            }
        };

        FutureTask<String> futureTask = new FutureTask<>(callable);

        Thread thread1 = new Thread(futureTask,"AA");
        thread1.start();

        String result = null;
        try {
            result = futureTask.get();
            System.out.println("结果是:" + result);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
